//-
//- Copyright (c) Microsoft. All rights reserved.
//- Licensed under the MIT license. See LICENSE file in the project root for full license information.
//-

extends ../layout

block js_doc_ready
  | var inviteInterfaceUpdateOnClick = function(){$('#openInviteButton').removeClass('btn-primary').addClass('btn-muted');$('#inviteAcceptedButton').removeClass('btn-muted').addClass('btn-primary');alert('On the next page press the green Join button.\n\nThen close the page and return here to continue onboarding to #{organization.name}.');return true;};
  | $('#openInviteButton').click(inviteInterfaceUpdateOnClick);
  | $('#openInviteButton2').click(inviteInterfaceUpdateOnClick);

block content
  .container
    if writeOrgFailureMessage
      .alert.alert-danger
        if showTwoFactorWarning
          h2 Two-factor authentication is required to continue
        else
          h2 GitHub API warning
        p.lead= writeOrgFailureMessage

    if state === 'pending' && showTwoFactorWarning

      p(style='margin-top:24px')
        | This organization has enabled GitHub's&nbsp;
        a(href='https://help.github.com/articles/requiring-two-factor-authentication-in-your-organization/', target='_new') two-factor authentication requirement
        |. As a result, you cannot join the org until you&nbsp;
        a(href='https://github.com/settings/two_factor_authentication/configure') turn on two-factor auth&nbsp;
        | with GitHub.

      form(method='post')
        ul.list-inline
          li
            a.btn.btn-primary(href='https://github.com/settings/two_factor_authentication/configure', target='_new') Configure 2FA on GitHub
          li
            input.btn.btn-default(type='submit', value='Validate 2FA and continue', title='Pending - you have already been invited')

      include twoFactorInstructions

    else if state == 'pending'
      if showApplicationPermissionWarning
        // Need to figure out what the right message is to show here

      h1 Action Required: You've been manually invited!

      p.lead GitHub has sent an invitation to <em>#{organization.name}</em>.
      p
        | For security purposes, GitHub requires you to accept the invitation directly on their web site.&nbsp;
        strong You must come back to this tab after accepting your invitation to continue setting up your open source teams and permissions.
      div.row
        div.col-md-6.col-lg-6
          h3 Step 1: Accept your invite from GitHub
          p
            | Open your invite on GitHub and press the green button.
          p
            a.btn.btn-lg.capitalize.btn-primary#openInviteButton(href='https://github.com/orgs/' + organization.name + '/invitation', target='_new') Open your #{organization.name} invitation
          h3 Step 2: Return back here
          p
            | After pressing the green Join button, close the GitHub site and click Continue on this page. We'll then take you to a security check the "Join Teams" experience.
          p
            a.btn.btn-lg.btn-muted#inviteAcceptedButton(href=organization.baseUrl + 'join' + (onboarding ? '?onboarding=' + onboarding : '')) I've accepted my invite on GitHub.com, continue...
        div.col-md-6.col-lg-6
          p(style='border:1px solid #ccc; padding:12px')
            a#openInviteButton2(target='_new', href='https://github.com/orgs/' + organization.name + '/invitation')
              img.img-responsive(src='/img/GitHubInvitation.png', title='A screenshot of what the GitHub invitation looks like. The experience is hosted outside of this portal and actually on GitHub.com', alt='A screenshot of what the GitHub invitation looks like. The experience is hosted outside of this portal and actually on GitHub.com')
            br
            | A sample GitHub invite. Press the green button and close the page.

    else if state == 'active'
      h1 You're now a member of #{organization.name}.
      p You are currently a member of this additional organization. No additional work is required to gain access to it.
      p If you need to join a specific team to gain additional permissions, you can use the Join a Team experience on this site.
      p
        a.btn.btn-primary(href='/teams') Join a team

    else
      div.row
        div.col-md-8.col-lg-8
          h1 Want to join #{organization.name}?
          if hasIncreasedScope
            form(method='post')
              p(style='margin-top:24px')
                input.btn.btn-primary.btn-huge(type='submit', value='Join ' + organization.name)
          else
            p.lead Quick way: Authorize us to join on your behalf
            p.
              Authorize this site to use the
              <a href="https://developer.github.com/v3/oauth/#scopes" target="_new"><code>org:write</code></a>
              permission and immediately join the organization.
            p
              a.btn.btn-primary.btn-huge(href='/' + organization.name + '/join/express' + (onboarding ? '?onboarding=' + onboarding : ''))
                | Join #{organization.name}
            hr
            p.lead Manual way: Follow this process
            ul
              li We'll explain how the GitHub invitation works.
              li An email invitation will be sent to you from GitHub.
              li You accept the invitation in on GitHub.com.
              li You come back to this site and continue onboarding.
            form(method='post')
              p
                input.btn.btn-muted-more.btn-lg(type='submit', value='Manually Join ' + organization.name)

          if onboarding
            p &nbsp;
            hr
            h3 Your onboarding progress
            h5
              | Sign in to your GitHub &amp; #{config.brand.companyName} accounts&nbsp;
              i.glyphicon.glyphicon-ok
            h5
              | Link your accounts&nbsp;
              i.glyphicon.glyphicon-ok
            h5.text-primary
              | Join your first GitHub organization
            h5
              | Multifactor security checkup
            h5
              | Profile review
            h5
              | Publish your membership <em>(optional)</em>
            h5
              | Join a team <em>(optional)</em>

        div.col-md-4.col-lg-4
          if orgAccount && orgAccount.organizationProfile
            - var orgUser = orgAccount.organizationProfile
            p
              img.img-thumbnail.img-responsive(src=orgAccount.avatar(400), alt=(orgUser.name || orgUser.login))
            h3= orgUser.name
            h4= orgUser.login
            p(style='margin-top:18px')
              a.btn.btn-sm.btn-muted(href='https://github.com/' + organization.name, target='_new')
                | Open on GitHub
            hr

            div.row
              div.col-md-6.col-lg-6
                if orgUser.company
                  h6 Company
                  p= orgUser.company
                if orgUser.location
                  h6 Location
                  p= orgUser.location
                if orgUser.email
                  h6 E-mail
                  p= orgUser.email
                if orgUser.blog
                  h6 On the Web
                  p
                    a(href=orgUser.blog, target='_new')= orgUser.blog
                if orgAccount.getProfileCreatedDate && orgAccount.getProfileCreatedDate()
                  h6 Created
                  p
                    time(datetime=orgAccount.getProfileCreatedDate().toISOString())= orgAccount.getProfileCreatedDate().toDateString()
                if orgAccount.getProfileUpdatedDate && orgAccount.getProfileUpdatedDate()
                  h6 Updated
                  p
                    time(datetime=orgAccount.getProfileUpdatedDate().toISOString())= orgAccount.getProfileUpdatedDate().toDateString()
                hr
                if organization.configuredOrganizationRepositoryTypes
                  h6 Supported Repository Types
                  ul.list-unstyled
                    li Public
                    if organization.configuredOrganizationRepositoryTypes == 'publicprivate' || organization.configuredOrganizationRepositoryTypes == 'private'
                      li Private
              div.col-md-6.col-lg-h6
                h6 Repositories
                if orgUser.public_repos
                  h2
                    = orgUser.public_repos + ' '
                    small Public
                    //- small Public
                if orgUser.total_private_repos
                  h2
                    = orgUser.total_private_repos + ' '
                    small Private

                hr
                h6 Remaining Repositories
                if orgUser.plan && orgUser.plan.private_repos
                  h2
                    = orgUser.plan.name + ' '
                    small Plan
                  h2
                      = (orgUser.plan.private_repos - orgUser.total_private_repos) + ' '
                      small Private
                h2
                  | &infin;&nbsp;
                  small Public
